/**
 * 
 */
package org.abettor.smartswt.factory;

/**
 * WidgetPropertyParameters类的代理
 * @author abettor
 *
 */
public class WidgetPropertyParametersProxy
{
	//	用于保存需要的参数信息
	private WidgetPropertyParameters wp = null;

	/**
	 * 默认构造函数，创建一个WidgetPropertyParameters对象
	 *
	 */
	public WidgetPropertyParametersProxy()
	{
		wp = new WidgetPropertyParameters();
	}

	/**
	 * 向WidgetPropertyParameters对象中添加参数
	 * @param clazz 要添加的参数的类的完整名称
	 * @param value 要添加的参数值字符串
	 * @throws ClassNotFoundException 
	 */
	public void addParameter(String clazz, String value)
	throws ClassNotFoundException
	{
		//	过滤并转换输入对象的类型
		Class type = null;
		Object obj = null;
		if("boolean".equals(clazz))
		{
			type = Boolean.TYPE;
			obj = new Boolean(value);
		}
		else if("byte".equals(clazz))
		{
			type = Byte.TYPE;
			obj = new Byte(value);
		}
		else if("char".equals(clazz))
		{
			type = Character.TYPE;
			obj = value.charAt(0);
		}
		else if("double".equals(clazz))
		{
			type = Double.TYPE;
			obj = new Double(value);
		}
		else if("float".equals(clazz))
		{
			type = Float.TYPE;
			obj = new Float(value);
		}
		else if("int".equals(clazz))
		{
			type = Integer.TYPE;
			obj = new Integer(value);
		}
		else if("long".equals(clazz))
		{
			type = Long.TYPE;
			obj = new Long(value);
		}
		else if("short".equals(clazz))
		{
			type = Short.TYPE;
			obj = new Short(value);
		}
		else if("string".equals(clazz))
		{
			type = String.class;
			obj = value;
		}
		else
		{
			type = Class.forName(clazz);
			//TODO 复杂数据类型（也就是“类”）怎么设置数值呢？
		}

		//	将对象添加倒属性对象中
		wp.addParameter(type, obj);
	}

	/**
	 * 获取WidgetProperty对象
	 * @return WidgetProperty对象的引用
	 */
	public WidgetPropertyParameters getWidgetProperty()
	{
		return wp;
	}
}
